package com.shyroke.service.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shyroke.entity.Email;
import com.shyroke.entity.EmailEnum;
import com.shyroke.mapper.EmailMapper;
import com.shyroke.service.EmailServiceI;

@Service
public class EmailServiceImpl implements EmailServiceI {

	@Autowired
	private EmailMapper emailMapper;
	
	@Override
	public List<Email> selectAll(Integer userId) {
		
		return emailMapper.selectAll(userId);
	}

	@Override
	public Email selectByID(Integer emailId) {
		return emailMapper.selectByPrimaryKey(emailId);
	}

	@Override
	public void update(Email email) {
		
		emailMapper.updateByPrimaryKeySelective(email);
		
	}

	@Override
	public List<Email> selectAllByPage(Integer userId, int beginIndex, int endIndex) {
		
		return emailMapper.selectAllByPage(userId,beginIndex,endIndex);
	}

	@Override
	public void save(Email email) {
		emailMapper.insert(email);
		
	}

	@Override
	public boolean isSend(Integer sendUserID, Integer receiveUserID, String type) {
		Email email = null;
		
		if(!EmailEnum.FRIEND.equals(type)) {
			email = new Email();  //方位添加邮件
			throw new RuntimeException("邮件类型只能是friend类型");
		}else {
			
			 email = emailMapper.isSend(sendUserID,receiveUserID,"friend");
		}
		
		return (email!=null)?true:false;
	}

	@Override
	public void deleteById(Integer id) {
		emailMapper.deleteByPrimaryKey(id);
		
	}

}
